home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / RTrace-1.0-src / light.c < prev    next >
Text File  |  1992-08-17  |  4KB  |  105 lines

  1. /*
  2.  * Copyright (c) 1988, 1992 Antonio Costa, INESC-Norte.
  3.  * All rights reserved.
  4.  *
  5.  * This code received contributions from the following people:
  6.  *
  7.  *  Roman Kuchkuda      - basic ray tracer
  8.  *  Mark VandeWettering - MTV ray tracer
  9.  *  Augusto Sousa       - overall, shading model
  10.  *  Craig Kolb          - lights
  11.  *
  12.  * Redistribution and use in source and binary forms are permitted
  13.  * provided that the above copyright notice and this paragraph are
  14.  * duplicated in all such forms and that any documentation,
  15.  * advertising materials, and other materials related to such
  16.  * distribution and use acknowledge that the software was developed
  17.  * by Antonio Costa, at INESC-Norte. The name of the author and
  18.  * INESC-Norte may not be used to endorse or promote products derived
  19.  * from this software without specific prior written permission.
  20.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  21.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23.  */
  24. #include "defs.h"
  25. #include "extern.h"
  26.  
  27. /**********************************************************************
  28.  *    RAY TRACING - Light - Version 7.0                               *
  29.  *                                                                    *
  30.  *    MADE BY    : Antonio Costa, INESC-Norte, October 1991           *
  31.  *    MODIFIED BY: Antonio Costa, INESC-Norte, October 1991           *
  32.  **********************************************************************/
  33.  
  34. /***** Lights *****/
  35. void
  36. get_point_light()
  37. {
  38.   int             i;
  39.   real            value;
  40.  
  41.   light[lights].light_type = POINT_LIGHT_TYPE;
  42.   light[lights].data = NULL;
  43.   get_valid(scene, &value, X_MIN, X_MAX, "LIGHT X");
  44.   light[lights].coords.x = value;
  45.   get_valid(scene, &value, Y_MIN, Y_MAX, "LIGHT Y");
  46.   light[lights].coords.y = value;
  47.   get_valid(scene, &value, Z_MIN, Z_MAX, "LIGHT Z");
  48.   light[lights].coords.z = value;
  49.   get_valid(scene, &value, -LIGHTING_FACTOR_MAX, LIGHTING_FACTOR_MAX,
  50.             "LIGHT BRIGHTNESS Red");
  51.   light[lights].brightness.r = ABS(value);
  52.   light[lights].attenuation[0] = (value >= 0.0);
  53.   get_valid(scene, &value, -LIGHTING_FACTOR_MAX, LIGHTING_FACTOR_MAX,
  54.             "LIGHT BRIGHTNESS Green");
  55.   light[lights].brightness.g = ABS(value);
  56.   light[lights].attenuation[1] = (value >= 0.0);
  57.   get_valid(scene, &value, -LIGHTING_FACTOR_MAX, LIGHTING_FACTOR_MAX,
  58.             "LIGHT BRIGHTNESS Blue");
  59.   light[lights].brightness.b = ABS(value);
  60.   light[lights].attenuation[2] = (value >= 0.0);
  61.   for (i = 0; i < LIGHT_CACHE_LEVEL_MAX; POSINC(i))
  62.     light[lights].cache_id[i] = NO_OBJECTS;
  63. }
  64. void
  65. get_dir_light()
  66. {
  67.   real            value;
  68.   dir_light_ptr   light_ptr;
  69.  
  70.   get_point_light();
  71.   light[lights].light_type = DIRECT_LIGHT_TYPE;
  72.   ALLOCATE(light_ptr, dir_light_struct, 1);
  73.   light[lights].data = (void_ptr) light_ptr;
  74.   get_valid(scene, &value, X_MIN, X_MAX, "LIGHT VECTOR X");
  75.   light_ptr->vector.x = -value;
  76.   get_valid(scene, &value, Y_MIN, Y_MAX, "LIGHT VECTOR Y");
  77.   light_ptr->vector.y = -value;
  78.   get_valid(scene, &value, Z_MIN, Z_MAX, "LIGHT VECTOR Z");
  79.   light_ptr->vector.z = -value;
  80.   if (LENGTH(light_ptr->vector) <= ROUNDOFF)
  81.     runtime_abort("no LIGHT Vector");
  82.   NORMALIZE(light_ptr->vector);
  83.   get_valid(scene, &value, 0.0, 180.0, "LIGHT ILLUMINATION Angle");
  84.   light_ptr->cos_angle = MIN(1.0 - ROUNDOFF,
  85.                              COS(DEGREE_TO_RADIAN(value)));
  86.   light_ptr->t = 1.0 / (1.0 - light_ptr->cos_angle);
  87.   get_valid(scene, &value, 1.0, LIGHTING_FACTOR_MAX, "LIGHT LIGHTING Factor");
  88.   light_ptr->factor = 1.0 / value;
  89. }
  90. void
  91. get_ext_light()
  92. {
  93.   real            value;
  94.   ext_light_ptr   light_ptr;
  95.  
  96.   get_point_light();
  97.   light[lights].light_type = EXTENDED_LIGHT_TYPE;
  98.   ALLOCATE(light_ptr, ext_light_struct, 1);
  99.   light[lights].data = (void_ptr) light_ptr;
  100.   get_valid(scene, &value, 0.0, X_MAX, "LIGHT Radius");
  101.   light_ptr->diameter = 2.0 * value;
  102.   get_valid(scene, &value, 1.0, 256.0, "LIGHT Samples");
  103.   light_ptr->samples = ROUND(value) - 1;
  104. }
  105.